package com.chunfeng.mypen.controller;

import com.chunfeng.mypen.entity.Feedback;
import com.chunfeng.mypen.result.JsonRequest;
import com.chunfeng.mypen.service.FeedbackService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 反馈Controller
 *
 * @author by 春风能解释
 * <p>
 * 2023/11/22
 */
@RestController
@RequestMapping("/feed")
@Api(value = "反馈控制层", tags = "反馈操作访问接口")
public class FeedbackController {
    /**
     * 反馈业务层
     */
    @Autowired
    private FeedbackService feedbackService;


    /**
     * 分类查询反馈
     *
     * @param current  当前页
     * @param size     每页长度
     * @param feedback 分类
     * @return JSON
     */
    @GetMapping
    @ApiOperation(value = "分类筛选反馈信息")
    public JsonRequest<List<Feedback>> lookFeedback(
            @ApiParam(value = "当前页数", required = true)
            @RequestParam Integer current,
            @ApiParam(value = "每页长度", required = true)
            @RequestParam Integer size,
            @ApiParam(value = "条件", required = true)
            Feedback feedback) {
        return feedbackService.lookAllFeedback(current, size, feedback);
    }


    /**
     * 新增一条反馈数据
     *
     * @param feedback 反馈信息
     * @return JSON
     */
    @PostMapping
    @ApiOperation(value = "新增一条反馈信息")
    public JsonRequest<Integer> insertOneFeedback(
            @ApiParam(value = "待添加的反馈信息", required = true)
            @RequestBody Feedback feedback) {
        return feedbackService.insertOneFeedBack(feedback);
    }

    /**
     * 修改一条反馈数据
     *
     * @param feedback 待修改的反馈信息
     * @return JSON
     */
    @PutMapping
    @ApiOperation(value = "修改一条反馈信息")
    public JsonRequest<Integer> updateOneFeedback(
            @ApiParam(value = "待修改的反馈信息", required = true)
            @RequestBody Feedback feedback) {
        return feedbackService.updateOneFeedback(feedback);
    }

    /**
     * 批量删除反馈
     *
     * @param feedbackId 反馈ID
     * @return JSON
     */
    @DeleteMapping
    @ApiOperation(value = "批量删除反馈信息")
    public JsonRequest<Integer> deleteFeedbacks(
            @ApiParam(value = "待删除的反馈ID", required = true)
            @RequestBody List<String> feedbackId) {
        return feedbackService.deleteFeedback(feedbackId);
    }
}
